using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.SupplyChain.Material;


namespace HengTong.ViewModel.SupplyChain.SysMaterialAttributeVms
{
    public partial class SysMaterialAttributeListVm : BaseListVm<SysMaterialAttributeView, SysMaterialAttributeSearcher>
    {

        protected override IEnumerable<IGridColumn<SysMaterialAttributeView>> InitGridHeader()
        {
            return new List<GridColumn<SysMaterialAttributeView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.IsKeyAttribute),
                this.MakeGridHeader(x => x.MaterialName),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.Order),
                this.MakeGridHeader(x => x.Values),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysMaterialAttributeView> GetSearchQuery()
        {
            var query = DC.Set<SysMaterialAttribute>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.IsKeyAttribute, x=>x.IsKeyAttribute)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .Select(x => new SysMaterialAttributeView
                {
				    ID = x.ID,
                    Name = x.Name,
                    IsKeyAttribute = x.IsKeyAttribute,
                    MaterialName = x.Material.Name,
                    Remark = x.Remark,
                    Order = x.Order,
                    Values = x.Values
                })
                .OrderByDescending(x => x.IsKeyAttribute)
                .ThenBy(x => x.Order)
                .ThenBy(x => x.Name);
            return query;
        }
    }

    public class SysMaterialAttributeView : SysMaterialAttribute{
        [Display(Name = "名称")]
        public String MaterialName { get; set; }

    }
}
